package se.olli.jonsered;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class ImageViewerActivity extends Activity implements OnClickListener {
	private int currentImg;
	private int [] images;
	private ImageView image, next, prev;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.image_viewer);

		Intent intent = getIntent();
		currentImg = intent.getIntExtra(GalleryActivity.IMAGE_ID, 0);
		images = intent.getIntArrayExtra(GalleryActivity.IMG_ARRAY);

		image = (ImageView) findViewById(R.id.image);
		next = (ImageView) findViewById(R.id.next);
		prev = (ImageView) findViewById(R.id.prev);
		
		image.setImageResource(images[currentImg]);
		next.setOnClickListener(this);
		prev.setOnClickListener(this);

	}
	public void onClick(View v) {
		if (v.getId() == next.getId()) {
			currentImg++;
			if(currentImg > 9)
				currentImg = 0;
			image.setImageResource(images[currentImg]);
		} else if (v.getId() == prev.getId()) {
			currentImg--;
			if(currentImg < 0)
				currentImg = 9;
			image.setImageResource(images[currentImg]);
		}
	}

}
